<template>
  <view>
    <view class="w100 rowscl rowsm pl-36 pr-36 pt-40">
      <view class="w-176 h-176 relative mb-90" @click="uploadImg()">
        <image :src="img ? img : '/static/wd_gr.png'" class="w100 h100 br-88" mode="" style="border: 2rpx solid #487EFF;">
        </image>
        <image src="/static/icon_grxxsc-1.png" class="w-52 h-52 absolute" style="bottom: 0;right: 0;" mode=""></image>
      </view>

      <view class="w100 rowsb rowsm trt fs-30 pb-16 mb-20" style="border-bottom: 1px solid #dcdcdc;">
        <view class="col888">姓名</view>
        <input type="text" placeholder="请输入姓名" disabled placeholder-class="fs-30 col333" v-model="userName">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 pt-30 pb-16 mb-20" style="border-bottom: 1px solid #dcdcdc;"
        v-if="flag == 'student'">
        <view class="col888">学号</view>
        <input type="number" placeholder="" disabled maxlength="11" placeholder-class="fs-30 col333"
          v-model="userInfo.stNumber">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 pt-30 pb-16 mb-20" style="border-bottom: 1px solid #dcdcdc;" v-else>
        <view class="col888">教工号</view>
        <input placeholder="" disabled maxlength="11" placeholder-class="fs-30 col333" v-model="userInfo.jsNumber">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 pt-30 pb-16 mb-20" style="border-bottom: 1px solid #dcdcdc;">
        <view class="col888">手机号</view>
        <input type="number" placeholder="请输入手机号" disabled maxlength="11" placeholder-class="fs-30 col333"
          v-model="phonenumber">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 pt-30 pb-16 mb-20" style="border-bottom: 1px solid #dcdcdc;">
        <view class="col888">学校</view>
        <input type="text" placeholder="请输入学校" disabled placeholder-class="fs-30 col333" v-model="userInfo.xxName">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 pt-30 pb-16 mb-20" style="border-bottom: 1px solid #dcdcdc;">
        <view class="col888">学院</view>
        <input type="text" placeholder="请输入学院" disabled placeholder-class="fs-30 col333" v-model="userInfo.xyName">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 pt-30 pb-16 mb-20" v-if="flag == 'student'"
        style="border-bottom: 1px solid #dcdcdc;">
        <view class="col888">专业</view>
        <input type="text" placeholder="请输入专业" disabled placeholder-class="fs-30 col333" v-model="userInfo.zyName">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 pt-30 pb-16 mb-20" v-if="flag == 'student'"
        style="border-bottom: 1px solid #dcdcdc;">
        <view class="col888">年级</view>
        <input type="text" placeholder="请输入年级" disabled placeholder-class="fs-30 col333" v-model="userInfo.njName">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 pt-30 pb-16 mb-20" v-if="flag == 'student'"
        style="border-bottom: 1px solid #dcdcdc;">
        <view class="col888">班级</view>
        <input type="text" placeholder="请输入班级" disabled placeholder-class="fs-30 col333" v-model="userInfo.bjName">
      </view>
      <view class="w100 rowsb rowsm trt fs-30 pt-30 pb-16 mb-20" style="border-bottom: 1px solid #dcdcdc;"
        v-if="flag == 'student'">
        <view class="col888">状态</view>
        <input type="text" placeholder=" " disabled placeholder-class="fs-30 col333" v-model="userInfo.status">
      </view>
    </view>

    <!-- <view class="w100 rowsc rowsm">
      <view class="w-300 h-84 br-36 rowsc rowsm colfff fs-30 fw-b" style="background: linear-gradient(to bottom,#4897FF,#4878FF);" @click="updateUserInfo()">确定</view>
    </view> -->
  </view>
</template>

<script>
export default {
  data() {
    return {
      img: '',
      uploadUrl: '',
      flag: '',
      userInfo: {},
      userName: '',
      phonenumber: ''
    };
  },
  onLoad() {
    this.flag = uni.getStorageSync('flag');
    // this.userInfo = this.flag == 'student' ? uni.getStorageSync('getInfo') : uni.getStorageSync('getInfo').user;
    // this.userName = this.userInfo.nickName || this.userInfo.name;
    // this.img = this.userInfo.avatar ? (this.$tools.avatarUrl + this.userInfo.avatar) : null;
    if (this.flag == 'student') {
      this.userInfo = uni.getStorageSync('getInfo');
      this.userName = this.userInfo.name;
      this.img = this.$tools.avatarUrl + this.userInfo.userImage;
    } else {
      this.userInfo = uni.getStorageSync('getInfo').user;
      this.userName = this.userInfo.nickName;
      this.img = this.$tools.avatarUrl + this.userInfo.avatar;
    }
    this.phonenumber = this.userInfo.phonenumber || this.userInfo.phone;
    this.userInfo.xxName = '临沂职业学院';
    // this.getUserInfo()
  },
  methods: {
    updateUserInfo() {
      if (!this.uploadUrl) return this.$tools.showtt('请上传头像')
      this.$tools.axiosFromToken('POST', 'prouser/update', { userImage: this.uploadUrl }, '加载中').then(res => {
        if (res.code != 200) return
        this.$tools.showtt('上传成功')
        // setTimeout(() => {
        //   this.$tools.goBack(1)
        // }, 1000)
      })
    },
    uploadImg() {
      uni.chooseImage({
        count: 1,
        success: (res) => {
          uni.uploadFile({
            url: this.$tools.httpOne + 'utils/ossUpload',
            filePath: res.tempFilePaths[0],
            header: {
              'Authorization': "Bearer " + sessionStorage.getItem('token')
              // 'token': sessionStorage.getItem('token')
            },
            name: 'file',
            success: (res1) => {
              console.log(res1);
              this.uploadUrl = JSON.parse(res1.data).url;
              this.img = this.$tools.avatarUrl + JSON.parse(res1.data).url;
              console.log(this.uploadUrl);
              console.log(this.img);
              this.updateUserInfo();
            }
          })
        }
      })
    },
    getUserInfo() {
      this.$tools.axiosFromToken('POST', 'prouser/getById', {}, '加载中').then(res => {
        if (res.code != 200) return this.$tools.showtt(res.msg)
        let { data } = res
        data.userImage = this.$tools.avatarUrl + data.userImage
        this.userInfo = data
        this.img = data.userImage
      })
    }
  }
}
</script>

<style lang="scss"></style>
